﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ReadyAppsTest.Models.Wiki;
using ReadyAppsTest.Data;
using System.Web.UI;
using ReadyApps.Wiki;
using System.Web.UI.WebControls;
using ReadyApps.Data;

namespace ReadyAppsTest.Controllers
{
    /// <summary>
    /// Summary description for WikiControllerTest
    /// </summary>
    [TestClass]
    public class WikiControllerTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Constructor Tests

        [TestMethod]
        public void WikiControllerConstructorTest()
        {
            TestWikiPageRequest pageRequest = new TestWikiPageRequest();
            TestWikiDataProvider dataProvider = new TestWikiDataProvider();
            Control owner = new Page();
            ControlCollection controls = new ControlCollection(owner);
            TestWikiUrlManager urlManager = new TestWikiUrlManager();
            //WikiController target = new WikiController(pageRequest, dataProvider, controls, urlManager);
            //PrivateObject targetWrapper = new PrivateObject(target);
            //Assert.AreEqual(pageRequest, targetWrapper.GetField("pageRequest"));
            //Assert.AreEqual(dataProvider, targetWrapper.GetField("dataProvider"));
            //Assert.AreEqual(controls, targetWrapper.GetField("controls"));
            //Assert.AreEqual(urlManager, targetWrapper.GetField("urlManager"));
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void WikiControllerPageRequestNullTest()
        {
            TestWikiPageRequest pageRequest = null;
            TestWikiDataProvider dataProvider = new TestWikiDataProvider();
            Control owner = new Page();
            ControlCollection controls = new ControlCollection(owner);
            TestWikiUrlManager urlManager = new TestWikiUrlManager();
            //WikiController target = new WikiController(pageRequest, dataProvider, controls, urlManager);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void WikiControllerDataProviderNullTest()
        {
            TestWikiPageRequest pageRequest = new TestWikiPageRequest();
            TestWikiDataProvider dataProvider = null;
            Control owner = new Page();
            ControlCollection controls = new ControlCollection(owner);
            TestWikiUrlManager urlManager = new TestWikiUrlManager();
            //WikiController target = new WikiController(pageRequest, dataProvider, controls, urlManager);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void WikiControllerControlsNullTest()
        {
            TestWikiPageRequest pageRequest = new TestWikiPageRequest();
            TestWikiDataProvider dataProvider = new TestWikiDataProvider();
            ControlCollection controls = null;
            TestWikiUrlManager urlManager = new TestWikiUrlManager();
            //WikiController target = new WikiController(pageRequest, dataProvider, controls, urlManager);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void WikiControllerUrlManagerNullTest()
        {
            TestWikiPageRequest pageRequest = new TestWikiPageRequest();
            TestWikiDataProvider dataProvider = new TestWikiDataProvider();
            Control owner = new Page();
            ControlCollection controls = new ControlCollection(owner);
            TestWikiUrlManager urlManager = null;
            //WikiController target = new WikiController(pageRequest, dataProvider, controls, urlManager);
        }

        #endregion

        #region Generate Controls Tests

        [TestMethod]
        public void GenerateControlsDataProviderTest()
        {
            TestWikiPageRequest pageRequest = new TestWikiPageRequest();
            pageRequest.SiteName = "site";
            pageRequest.FullPath = "/full/path/";
            pageRequest.RequestedPage = "page";
            TestWikiDataProvider dataProvider = new TestWikiDataProvider();
            dataProvider.WikiPageData = null;
            Control owner = new Page();
            ControlCollection controls = new ControlCollection(owner);
            TestWikiUrlManager urlManager = new TestWikiUrlManager();
            //WikiController target = new WikiController(pageRequest, dataProvider, controls, urlManager);
            //target.CreateControls();
            //Assert.AreEqual(pageRequest.SiteName, dataProvider.GetWikiPageData_siteName);
            //Assert.AreEqual(pageRequest.FullPath, dataProvider.GetWikiPageData_folder);
            //Assert.AreEqual(pageRequest.RequestedPage, dataProvider.GetWikiPageData_pageName);
        }

        [TestMethod]
        public void GenerateControlsNonExistentPageTest()
        {
            TestWikiPageRequest pageRequest = new TestWikiPageRequest();
            pageRequest.SiteName = "site";
            pageRequest.FullPath = "/full/path/";
            pageRequest.RequestedPage = "page";
            TestWikiDataProvider dataProvider = new TestWikiDataProvider();
            dataProvider.WikiPageData = null;
            Control owner = new Page();
            ControlCollection actualControls = new ControlCollection(owner);
            TestWikiUrlManager urlManager = new TestWikiUrlManager();
            //WikiController target = new WikiController(pageRequest, dataProvider, actualControls, urlManager);
            //target.CreateControls();

            //WikiPage page = new WikiPage(urlManager);
            //page.GenerateWikiComponentsForNonExistentPage();
            //ControlCollection expectedControls = new ControlCollection(owner);
            //foreach (var control in page.GetWikiComponents())
            //{
            //    expectedControls.Add(control.GetControl());
            //}
            //Assert.AreEqual(expectedControls.Count, actualControls.Count);
            //CollectionAssert.AllItemsAreInstancesOfType(actualControls, typeof(Literal));
            //for (int i = 0; i < expectedControls.Count; i++)
            //{
            //    Assert.AreEqual(((Literal)expectedControls[i]).Text, ((Literal)actualControls[i]).Text);
            //}
        }

        [TestMethod]
        public void GenerateControlsPageDataTest()
        {
            TestWikiPageRequest pageRequest = new TestWikiPageRequest();
            pageRequest.SiteName = "site";
            pageRequest.FullPath = "/full/path/";
            pageRequest.RequestedPage = "page";
            TestWikiDataProvider dataProvider = new TestWikiDataProvider();
            string content = "content";
            dataProvider.WikiPageData = new WikiPageData(1, 1, "page", "title", content);
            Control owner = new Page();
            ControlCollection actualControls = new ControlCollection(owner);
            TestWikiUrlManager urlManager = new TestWikiUrlManager();
            //WikiController target = new WikiController(pageRequest, dataProvider, actualControls, urlManager);
            //target.CreateControls();

            //WikiPage page = new WikiPage(urlManager);
            //page.GenerateWikiComponentsFromPageData(dataProvider.WikiPageData);
            //ControlCollection expectedControls = new ControlCollection(owner);
            //foreach (var control in page.GetWikiComponents())
            //{
            //    expectedControls.Add(control.GetControl());
            //}
            //Assert.AreEqual(expectedControls.Count, actualControls.Count);
            //CollectionAssert.AllItemsAreInstancesOfType(actualControls, typeof(Literal));
            //for (int i = 0; i < expectedControls.Count; i++)
            //{
            //    Assert.AreEqual(((Literal)expectedControls[i]).Text, ((Literal)actualControls[i]).Text);
            //}
        }

        #endregion
    }
}
